import { Module } from 'vuex'
import { IRootState } from '../../type'
import { ISystemState } from './type'
import { getPageListData } from '@/service/system/system'

const systemModule: Module<ISystemState, IRootState> = {
  namespaced: true,
  state() {
    return {
      userList: [],
      userCount: 0
    }
  },
  mutations: {
    changeUserList: (state, payload) => {
      state.userList = payload
    },
    changeUserCount: (state, payload) => {
      state.userCount = payload
    }
  },
  actions: {
    async getpagelist({ commit }, payload) {
      const pageResult = await getPageListData(
        payload.pageUrl,
        payload.queryInfo
      )
      const { list, totalCount } = pageResult.data

      commit('changeUserList', list)
      commit('changeUserCount', totalCount)
    }
  }
}

export default systemModule
